package com.xyh.web;

import com.xyh.pojo.PageRequest;
import com.xyh.pojo.Tag;
import com.xyh.service.BlogService;
import com.xyh.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class TagShowController {
    @Autowired
    private TagService tagService;
    @Autowired
    private BlogService blogService;
    @GetMapping("/tags/{id}")
    public String tags(PageRequest pageRequest,@PathVariable Long id, Model model){
        List<Tag> tags = tagService.getTagTop(10000);
        if (id==-1) {
            id= tags.get(0).getId();
        }
        model.addAttribute("tags", tags);
        model.addAttribute("page", blogService.getPageByTagId(pageRequest,id));
        model.addAttribute("activeTagId", id);
        return "tags";
    }
}
